package com.project.service.service;

import com.project.service.bean.UserBean;
import com.project.service.dao.IUserDao;
import com.project.service.server.Request;
import com.project.service.server.Response;
import com.project.service.server.Servlet;
import com.project.service.util.DaoFactory;
import com.project.service.util.WebServlet;

/**
 * 按ID查询用户业务组件
 */
@WebServlet("findById")
public class FindByIdService implements Servlet {
    private IUserDao dao = (IUserDao) DaoFactory.getDao("IUserDao");

    public void service(Request req, Response resp){
        //得到表单数据
        int id = Integer.parseInt(req.getParameter("id"));
        //调用持久方法，得到结果
        UserBean user = dao.findById(id);

        String str = "<form action='update'>";
        str += "<input type='hidden'  name='id' value='"+id+"'>";
        str += "用户名："+user.getName()+"<br>";
        str += "密码：<input type='text' value='" + user.getPwd()+ "' name='pwd'><br>";
        str += "生日："+user.getBirthday()+"<br>";
        str += "<input type='submit' value='修改'>";

        str += "</form>";

        resp.sendMessage(str);
    }
}
